#include "xMappingNode.h"
#include "xNodeType.h"
#include "xNodeType_vmcollector.h"
#include "vmLibrary.h"
#include "xParameterPack.h"
#include "all_entries.h"
#include "xInMappingPort.h"
#include "xOutMappingPort.h"

using namespace std; 
void xNodeType_vmcollector::setupPorts() {

	assert(_parent != NULL);

	_parent->_inports.push_back(new xInMappingPort(_parent,"vm","vm",CLASS_REQUIRED,"NULL",CATEGORY_OTHER));
	_parent->_outports.push_back(new xOutMappingPort(_parent,"vms","vms",CLASS_REQUIRED,"NULL",CATEGORY_OTHER ));

}

xParameter xNodeType_vmcollector::toXParameter(string type, xOutMappingPort* linked_op) {
	//	a vmcollector typically has only one output port
	//  so we ignore the linked_op
	xParameter childxp ;
	xParameter xp ;

	xp.type = "vms" ;
	for (int i=0; i< _parent->getInportSize(); i++) {
		xInMappingPort *inp = _parent->getInPort(i);
		childxp = inp->toXParameter();
		assert(childxp.type == "vm");
		xp.val_vms.push_back(childxp.val_vm);
	}
	return xp ;
}

string xNodeType_vmcollector::toMDString(MDSType type) {

	ostringstream MDSstr ;
	if ( type == xNodeType::NormalMDSFormat){
		MDSstr <<  "node " << _parent->getSerialNo() << " vmcollector " << "NULL" << " " << "NULL" << endl ; 
	} else if ( type == xNodeType::ParameterizedMDSFormat){
		MDSstr << "ADD_NODE " <<"node " << "SN" << _parent->getSerialNo() << " vmcollector " << "NULL" << " " << "NULL" << endl ; 
	} else {
		assert(false);
	}
	
	return MDSstr.str();
}
int  xNodeType_vmcollector::parseMDString(vector<string>& tokens, int start_index) {
	int i = start_index ;
	assert(tokens[i] == "node");
	string serialno = tokens[i+1] ;
	assert(tokens[i+2] == "vmcollector");
	string nodetype = tokens[i+3] ; assert(nodetype == "NULL");
	string wopname = tokens[i+4] ; assert(wopname == "NULL");
	this->setInportFixed(false);
	this->setOutportFixed(true);
	this->getParent()->deletePort(0);
	return 5 ;
}
bool xNodeType_vmcollector::verify_rhs_link(xOutMappingPort *left, xInMappingPort *right, xNodeType* rightnode) {

	if (left->getType() == right->getType()) return true ;
	return false ;
}
bool xNodeType_vmcollector::verify_lhs_link(xOutMappingPort *left, xNodeType* leftnode, xInMappingPort *right) {
	if (left->getType() == right->getType()) return true ;
	return false ;
}